<?php
defined("_JEXEC") or die("Restricted access");

jimport("joomla.application.component.model");

class JoomlaIniTranslatorModelJoomlaIniTranslator extends JModel
{
	var $_data;

	function _buildQuery() {
		$query = "SELECT * FROM #__joomlainitranslator";
		return $query;
	}

	function getData() {
		if (empty($this->_data)) {
			$query = $this->_buildQuery();
			$this->_data = $this->_getList($query);
		}
		return $this->_data;
	}
	
	function store() {
		$row =& $this->getTable();
		$data = JRequest::get('post');
		
		if (!$row->bind($data)) {
			$this->setError($row->getError());
			return false;
		}
		$row->created = time();
		//var_dump($row); die;
		
		// Make sure the hello record is valid
		if (!$row->check()) {
			$this->setError($row->getError());
			return false;
		}

		// Store the web link table to the database
		if (!$row->store()) {
			$this->setError($row->getError());
			return false;
		}

		return true;
	}
	
	function changeStatus($data, $status) {
		$row =& $this->getTable();
		$data->status = $status;
		if (!$row->bind($data)) {
			$this->setError($row->getError());
			return false;
		}
		
		if (!$row->check()) {
			$this->setError($row->getError());
			return false;
		}
		
		if (!$row->store()) {
			$this->setError($row->getError());
			return false;
		}
		return true;
	}
	
	function delete() {
		$cids = JRequest::getVar( 'cid', array(0), 'post', 'array' );

		$row =& $this->getTable();

		if (count( $cids )) {
			foreach($cids as $cid) {
				if (!$row->delete( $cid )) {
					$this->setError( $row->getError() );
					return false;
				}
			}
		}
		return true;
	}
	
	function find($id) {
		$table = $this->getTable();
		
		$query = 'SELECT *'
		. ' FROM `#__joomlainitranslator`'
		. ' WHERE `id` = '.$id
		. ' LIMIT 1';
		$this->_db->setQuery( $query );

		if (!($row = $this->_db->loadObjectList())) {
			$this->setError( $table->getError() );
			return false;
		}
		return $row;
	}
}
?>